//
//  HumanViewController.swift
//  CocoaPodsDemo
//
//  Created by satoshi_umaM1 on 2022/2/17.
//

import UIKit

class HumanViewController: UIViewController {
    private var h: HumanView!
    private var subTitle: UILabel!
    override func viewDidLoad() {
        super.viewDidLoad()

        view.backgroundColor = UIColor.white

        h = HumanView()
        h.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
        h.delegate = self
        view.addSubview(h)

        subTitle = UILabel()
        subTitle.frame = CGRect(x: 0, y: 68, width: view.frame.size.width, height: UIAdapter(16))
        subTitle.textColor = UIColor(red: 24 / 255, green: 24 / 255, blue: 24 / 255, alpha: 1)
        subTitle.font = UIFont.systemFont(ofSize: UIAdapter(14))
        subTitle.textAlignment = .center
        subTitle.text = "人体结构图"
        view.addSubview(subTitle)
    }
}

extension HumanViewController: HumanViewDelegate {
    func returnClickCellIndex(type: Int) {
        print("---type---\(type)")

        if type == 10 {
            subTitle.text = "心脏"
        } else {
            subTitle.text = "胃"
        }

        h.setNeedsDisplay()
    }
    
    func returnReload() {
        h.setNeedsDisplay()
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////    PCH   ////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// MARK: - 获取画iPhone nav和tabbar高度

let SCREEN_WIDTH = UIScreen.main.bounds.size.width
let SCREEN_HEIGHT = UIScreen.main.bounds.size.height

let mc_Is_iphone = (UI_USER_INTERFACE_IDIOM() == .phone)
let mc_Is_iphoneX = (SCREEN_WIDTH >= 375.0) && SCREEN_HEIGHT >= 812.0 && mc_Is_iphone

/// 状态栏和导航栏总高度
var mcNavBarAndStatusBarHeight = (mc_Is_iphoneX ? (44.0 + STATUSBAR_HEIGHT()) : (44.0 + STATUSBAR_HEIGHT()))
/// TabBar高度
let mcTabBarHeight = (mc_Is_iphoneX ? (49.0 + INDICATOR_HEIGHT()) : (49.0 + INDICATOR_HEIGHT()))
/// 状态栏 高度
let mcNavBarSafeAreaHeight = (mc_Is_iphoneX ? CGFloat(44.0) : CGFloat(20.0))
/// Tabbar 安全距离 高度
let mcTabbarSafeAreaHeight = (mc_Is_iphoneX ? INDICATOR_HEIGHT() : INDICATOR_HEIGHT())
/// 导航栏 高度
let mcNavBarHeight = CGFloat(44.0)
///  Nav 和 Tabbar 总高度
let mcNavAndTabHeight = (mcNavBarAndStatusBarHeight + mcTabBarHeight)
/// Status 高度
var mcStatusBarHeight = (mc_Is_iphoneX ? STATUSBAR_HEIGHT() : STATUSBAR_HEIGHT())

// MARK: -  状态栏

func STATUSBAR_HEIGHT() -> CGFloat {
    if #available(iOS 13.0, *) {
        let statusBarManager = UIApplication.shared.windows.first?.windowScene?.statusBarManager
        return (statusBarManager?.statusBarFrame.size.height)!
    } else {
        let statusBarHeight = UIApplication.shared.statusBarFrame.size.height
        return statusBarHeight
    }
}

// MARK: -  底部指示条

func INDICATOR_HEIGHT() -> CGFloat {
    if #available(iOS 11.0, *) {
        let safeAreaInsets = UIApplication.shared.delegate?.window??.safeAreaInsets
        return safeAreaInsets!.bottom
    } else {
        return UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0).bottom
    }
}

// MARK: - 计算 机型比例

/// 根据机型比例返回合理的数值
/// - Parameter Original: 原始值
/// - Returns: 计算后的返回值
func UIAdapter(_ original: CGFloat) -> CGFloat {
    let scale = 375 / SCREEN_WIDTH // iphone 6
    return round(CGFloat(original) / scale) // 四舍五入
}

func MCLog<T>(_ message: T, file: String = #file, line: Int = #line) {
    #if DEBUG
        let filepath = (file as NSString).lastPathComponent
        //        let fun = #function
        print("---------------------------- 打印开始 ----------------------------\n\(line)行 - \(filepath) - 输出:\n\(message)\n----------------------------- 结束 ------------------------------\n\n\n")
    #endif
}
